import java.sql.*;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class JDBCTest_Del {
    public static void main(String[] args) {
        Statement stmt = null;
        Connection conn = null;
        try{

//            这里都只采用一种方式

            //        1.注册驱动
            DriverManager.registerDriver(new com.mysql.jdbc.Driver());

            //        2.获取连接
            conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456");
            //        3.获取数据库操作对象（statement专门执行sql语句）
            stmt = conn.createStatement();

            //        4.执行sql
            String sql = "delete from table1 where id=30";
            int count = stmt.executeUpdate(sql);
            System.out.println(count==1?"删除成功":"删除失败");

        }catch(SQLException e){
            e.printStackTrace();
        }finally {
//            6.释放资源(分别释放)
            try {
                if(stmt != null) {
                    stmt.close();
                }
            }catch (SQLException e){
                e.printStackTrace();
            }
            try {
                if(conn != null){
                    conn.close();
                }
            }catch (SQLException e){
                e.printStackTrace();
            }
        }


    }
}